package com.byit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.byit.domain.AppApplication;
import com.byit.domain.AppApplictionMenu;
import com.byit.domain.AppSensitiveWords;
import com.byit.mapper.AppApplicationMapper;
import com.byit.mapper.AppApplictionMenuMapper;
import com.byit.service.IAppApplicationService;
import com.byit.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 应用表 服务实现类
 * </p>
 *
 * @author wumin
 * @since 2019-01-03
 */
@Service
public class AppApplicationServiceImpl extends ServiceImpl<AppApplicationMapper, AppApplication> implements IAppApplicationService {

    @Autowired
    private AppApplictionMenuMapper appApplictionMenuMapper;
    
    @Override
    public Page<JSONObject> selectDataPage(Page<AppApplication> pageInfo, Map<String, Object> map) {
        List<JSONObject> list = this.baseMapper.selectDataPage(pageInfo,map);
        Page<JSONObject> page = PageUtil.transform(pageInfo);
        page.setRecords(list);
        return page;
    }

    @Override
    public Map<String, Object> selectDataCount() {
        AppApplictionMenu appApplictionMenu = new AppApplictionMenu();
        EntityWrapper<AppApplictionMenu> entityWrapper = new EntityWrapper<>(appApplictionMenu);
        entityWrapper.where("is_del={0}",0);
        Integer functionCount = appApplictionMenuMapper.selectCount(entityWrapper);

        AppApplication application = new AppApplication();
        EntityWrapper<AppApplication> applicationWrapper = new EntityWrapper<>(application);
        applicationWrapper.where("is_del={0}",0);

        Integer applicationCount = this.baseMapper.selectCount(applicationWrapper);
        Map<String,Object> map = new HashMap<String,Object>();
        //功能数量
        map.put("functionCount",functionCount);
        //应用数量
        map.put("applicationCount",applicationCount);
        return map;
    }

    @Override
    public List<JSONObject> selectByApp(Map<String, Object> map) {
        return this.baseMapper.selectByApp(map);
    }
}
